package com.xpgk.mvc.statistic.loseSizeList;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.codeSet.Code;
import com.xpgk.mvc.organization.Organization;

public class LoseSizeListController extends BaseController {

	LoseSizeListService loseSizeListService;
	
	public void index(){
		setAttr("curOrgan", Organization.dao.findById(getCUserOrganIds()));
		setAttr("parts", Code.cacheGetChild(Code.fwbw_ids));
		render("loseSizeList.html");
	}
	
	/*
	 * 顾客数据查询
	 */
	public void customerDataQuery() throws Exception{
		String organIdsEmployee = getPara("organIdsEmployee");
		String arrivedMinDate = getPara("arrivedMinDate");
		String hybh = getPara("hybh");
		String customerName = getPara("customerName");
		String customerPhone = getPara("customerPhone");
		List<Record> result = loseSizeListService.customerDataQuey(organIdsEmployee, arrivedMinDate,hybh,customerName,customerPhone);
		
		for(Record r : result){
			System.out.println(r);
		}
		
		
		renderJson(result);
	}
	/*
	 * 顾客数据Excel导出
	 */
	public void excel() throws Exception{
		List<Code> parts = Code.cacheGetChild(Code.fwbw_ids);
		List<List<Code>> cacheGetChild = new ArrayList<List<Code>>();
		for(Code r : parts){
			cacheGetChild.add(Code.cacheGetChild(r.getStr("ids")));
		}
		
		String organIdsEmployee = getPara("organIdsEmployee");
		String arrivedMinDate = getPara("arrivedMinDate");
		String hybh = getPara("hybh");
		String customerName = getPara("customerName");
		String customerPhone = getPara("customerPhone");
		List<Record> result = loseSizeListService.customerDataQuey(organIdsEmployee, arrivedMinDate,hybh,customerName,customerPhone);
		
		Organization organ = Organization.dao.findById(organIdsEmployee);//门店
		String search_organIdsEmployee =organ.getStr(Organization.column_name).equals("")?"":("店面名称："+organ.getStr(Organization.column_name)+"，");
		
		String search = search_organIdsEmployee+"日期："+arrivedMinDate+",会员编号："+hybh+",顾客姓名："+customerName+",顾客手机："+customerPhone;
		render(new LoseSizeListXLS(cacheGetChild,parts,result, "顾客减尺排名表",search));
	}
	/*
	 * 查询减尺类型
	 */
//	public void querysizetype(){
//		String sqlMy = getSqlMy(LoseSizeListSQL.losesizelist_querysizetype);
//		List<Record> result = Db.find(sqlMy);
//		renderJson(result);
//	}
	
}
